<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Setting extends MY_Controller {


	 	public function __construct()
	{
		parent::__construct();
		$this->load->model('Setting_model');

	}
	public function index()
	{
		/*获取设置信息并放入数组*/
	    $data = array(
	         'setting' => $this->Setting_model->get_setting()
	        );
		/*分配变量，显示视图*/
	    $this->load->view('setting',$data);
	}
	
	public function site_update()
	{
		  /*设置表单的客户端验证规则*/
		  $this->form_validation->set_rules('sitename', '站点名称', 'trim|required',
	      array(
			'required'  => '必须填写站点名称!'
		  )
	     	);
		  $this->form_validation->set_rules('siteurl', '站点地址', 'trim|required',
	      array(
			'required'  => '必须填写站点地址!'
		  )
	     	);
		  $this->form_validation->set_rules('keywords', 'SEO关键词', 'trim|required',
	      array(
			'required'  => '必须填写SEO关键词!'
		  )
	     	);
		  $this->form_validation->set_rules('description', 'SEO描述', 'trim|required',
	      array(
			'required'  => '必须填写SEO描述!'
		  )
	     	);			
		/*判断表单客户端验证结果*/
		if ($this->form_validation->run() == FALSE){
			 /*表单的客户端验证失败，显示提示信息，并跳转至设置信息页面*/
			 $this->formTips(validation_errors(),"setting/index",'2');
		} else {
		/*表单的客户端验证成功，将表单内信息存入数组内*/	
		$data = array(
		    'sitename'    => $this->input->post('sitename'),
			'siteurl'    => $this->input->post('siteurl'),
			'keywords'	  => $this->input->post('keywords'),
			'description' => $this->input->post('description'),
			'code'	      => $this->input->post('code')

		);
		  /*调用模型中的方法更新数据库的数据*/
	      $query = $this->Setting_model->update($data);
		  /*根据返回的结果判断修改是否成功并作出提示*/
          if(!$query){
			  /*跳转至设置信息页面*/
			  $this->formTips('没有任何更改',"setting/index",'2');  
		        }else{
			  $this->formTips('修改成功',"setting/index",'2');  
		  }
		}
		

	} 

	
	
	
	
}
